import { Chessman } from "./Chessman";

export default class Cannon extends Chessman {
  constructor(chessName, camp, x, y, key, chessId) {
    super(chessName, camp, x, y, key, chessId);
  }

  predictionMove(chessList, path?) {
    const res = [];
    const temp = [];
    const pathResolve = this.translate(temp, chessList);
    const boomPath = [
      [null, this.y],
      [null, this.y],
      [this.x, null],
      [this.x, null],
    ];
    if (path) {}
    chessList.forEach((item) => {
      if (item.y === this.y) {
        if (item.x < pathResolve.startX) {
          // 左架炮
          if (boomPath[0][0] === null) {
            boomPath[0][0] = item.x;
          } else if (boomPath[0][0] < item.x) {
            boomPath[0][0] = item.x;
          }
        } else if (item.x > pathResolve.endX) {
          // 右架炮
          if (boomPath[1][0] === null) {
            boomPath[1][0] = item.x;
          } else if (boomPath[1][0] > item.x) {
            boomPath[1][0] = item.x;
          }
        }
      }
      if (item.x === this.x) {
        if (item.y < pathResolve.startY) {
          // 上架炮
          if (boomPath[2][1] === null) {
            boomPath[2][1] = item.y;
          } else if (boomPath[2][1] < item.y) {
            boomPath[2][1] = item.y;
          }
        } else if (item.y > pathResolve.endY) {
          // 下架炮
          if (boomPath[3][1] === null) {
            boomPath[3][1] = item.y;
          } else if (boomPath[3][1] > item.y) {
            boomPath[3][1] = item.y;
          }
        }
      }
    });
    temp.push(...boomPath.filter((item) => item[0] != null && item[1] != null));

    res.push(...this.filterChessman(temp, [...chessList]));
    return { data: this, path: res };
  }
}
